var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__decorate) ||
        function (t, e, o, n) {
            var r,
                a = arguments.length,
                i = a < 3 ? e : null === n ? (n = Object.getOwnPropertyDescriptor(e, o)) : n;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, n);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (r = t[s]) && (i = (a < 3 ? r(i) : a > 3 ? r(e, o, i) : r(e, o)) || i);
            return a > 3 && i && Object.defineProperty(e, o, i), i;
        },
    a =
        (this && this.__awaiter) ||
        function (t, e, o, n) {
            function r(t) {
                return t instanceof o
                    ? t
                    : new o(function (e) {
                          e(t);
                      });
            }
            return new (o || (o = Promise))(function (o, a) {
                function i(t) {
                    try {
                        c(n.next(t));
                    } catch (t) {
                        a(t);
                    }
                }
                function s(t) {
                    try {
                        c(n.throw(t));
                    } catch (t) {
                        a(t);
                    }
                }
                function c(t) {
                    t.done ? o(t.value) : r(t.value).then(i, s);
                }
                c((n = n.apply(t, e || [])).next());
            });
        },
    i =
        (this && this.__generator) ||
        function (t, e) {
            var o,
                n,
                r,
                a,
                i = {
                    label: 0,
                    sent: function () {
                        if (1 & r[0]) throw r[1];
                        return r[1];
                    },
                    trys: [],
                    ops: []
                };
            return (
                (a = {next: s(0), throw: s(1), return: s(2)}),
                "function" == typeof Symbol &&
                    (a[Symbol.iterator] = function () {
                        return this;
                    }),
                a
            );
            function s(t) {
                return function (e) {
                    return c([t, e]);
                };
            }
            function c(a) {
                if (o) throw new TypeError("Generator is already executing.");
                for (; i; )
                    try {
                        if (
                            ((o = 1),
                            n &&
                                (r =
                                    2 & a[0]
                                        ? n.return
                                        : a[0]
                                        ? n.throw || ((r = n.return) && r.call(n), 0)
                                        : n.next) &&
                                !(r = r.call(n, a[1])).done)
                        )
                            return r;
                        switch (((n = 0), r && (a = [2 & a[0], r.value]), a[0])) {
                            case 0:
                            case 1:
                                r = a;
                                break;
                            case 4:
                                return i.label++, {value: a[1], done: !1};
                            case 5:
                                i.label++, (n = a[1]), (a = [0]);
                                continue;
                            case 7:
                                (a = i.ops.pop()), i.trys.pop();
                                continue;
                            default:
                                if (!(r = (r = i.trys).length > 0 && r[r.length - 1]) && (6 === a[0] || 2 === a[0])) {
                                    i = 0;
                                    continue;
                                }
                                if (3 === a[0] && (!r || (a[1] > r[0] && a[1] < r[3]))) {
                                    i.label = a[1];
                                    break;
                                }
                                if (6 === a[0] && i.label < r[1]) {
                                    (i.label = r[1]), (r = a);
                                    break;
                                }
                                if (r && i.label < r[2]) {
                                    (i.label = r[2]), i.ops.push(a);
                                    break;
                                }
                                r[2] && i.ops.pop(), i.trys.pop();
                                continue;
                        }
                        a = e.call(t, i);
                    } catch (t) {
                        (a = [6, t]), (n = 0);
                    } finally {
                        o = r = 0;
                    }
                if (5 & a[0]) throw a[1];
                return {value: a[0] ? a[1] : void 0, done: !0};
            }
        };
Object.defineProperty(o, "__esModule", {value: !0});
var s = t("EventData"),
    c = t("LoadTask"),
    l = cc._decorator,
    u = l.ccclass,
    p = (l.property, l.menu),
    f = (function (t) {
        function e() {
            return (null !== t && t.apply(this, arguments)) || this;
        }
        return (
            n(e, t),
            (e.prototype.onLoad = function () {
                (this.url = new s.default("")), (this.loadtask = new c.default(cc.SpriteFrame));
            }),
            (e.prototype.onEnable = function () {
                null == this.sprite && (this.sprite = this.getComponent(cc.Sprite)),
                    this.url.on(this, this.on_url_change, !0);
                var t = this.getComponent(cc.Widget);
                t &&
                    (this.updateWidget = function () {
                        t.updateAlignment();
                    });
            }),
            (e.prototype.onDisable = function () {
                this.url.off(this, this.on_url_change);
            }),
            (e.prototype.on_url_change = function () {
                return a(this, void 0, void 0, function () {
                    var t, e;
                    return i(this, function (o) {
                        switch (o.label) {
                            case 0:
                                return (t = this.url.value) == this.loadtask.url
                                    ? [3, 3]
                                    : "" != t
                                    ? [3, 1]
                                    : (this.loadtask.destory(),
                                      (this.loadtask = new c.default(cc.SpriteFrame)),
                                      (this.sprite.spriteFrame = null),
                                      [3, 3]);
                            case 1:
                                return [4, this.loadtask.load(t)];
                            case 2:
                                (e = o.sent()),
                                    this.sprite &&
                                        ((this.sprite.spriteFrame = e), this.updateWidget && this.updateWidget()),
                                    (o.label = 3);
                            case 3:
                                return [2];
                        }
                    });
                });
            }),
            (e = r([u, p("面板/SpriteLoad")], e))
        );
    })(cc.Component);
o.default = f;
